<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/reset.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />

</head>
<body>

  <div class="aui-content">
    <div class="aui-list aui-form-list aui-font-size-18">
      <div class="aui-list-item aui-padded-t-15 aui-padded-b-15 ">
        <div class="aui-list-item-label" >
          操作人
        </div>
        <div class="aui-list-item-input">
            <input type="text" placeholder="输入用户" id="username" readonly="readonly">
        </div>
      </div>
      <div class="aui-list-item aui-padded-t-15 aui-padded-b-15 ">
          <div class="aui-list-item-inner" >
            <div class="aui-list-item-label" >
            仓库号
            </div>
            <div class="aui-list-item-input" tapmode="hover" onclick="openSelect();">
                <input type="text" placeholder="请选择仓库" id="chtxt" readonly="readonly" >
                <input type="hidden" id="chid">
            </div>
          </div>
      </div>
      <div class="aui-list-item aui-padded-t-15 aui-padded-b-15 ">
        <div class="aui-list-item-label" >
        货位
        </div>
        <div class="aui-list-item-input">
            <input type="number" placeholder="输入货位" id="hw">
        </div>
      </div>
      <div class="aui-list-item aui-padded-t-15 aui-padded-b-15 ">
        <div class="aui-list-item-label" >
        模式：
        </div>
        <div class="aui-list-item-input">
            <input type="text" placeholder="选择模式" id="ms">
        </div>
      </div>
      <div class="aui-list-item aui-padded-t-15 aui-padded-b-15 ">
        <div class="aui-list-item-label" >
          同步数量
        </div>
        <div class="aui-list-item-input ">
            <input type="number" class="aui-text-danger" placeholder="同步数量" id="count" readonly="readonly">
        </div>
      </div>
    </div>
    <div class="aui-list-item aui-list-item-center aui-margin-t-15 aui-padded-15 ">
           <div class="aui-btn aui-btn-block aui-btn-info" tapmode onclick="synchData()" >提交同步</div>
    </div>
  </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/aui-toast.js"></script>
<script type="text/javascript" src="../script/aui-dialog.js"></script>
<script trpe="text/javascript">
  var codeData,toast,user,mstxt,mss=["待入库条码","待出库条码","已入库条码","已出库条码"];
  apiready =function(){
    api.parseTapmode();
    toast = new auiToast();
    init();


  };

  function init (){
    user=$api.getStorage(cacheUser);
    $api.dom('#ms').value=mss[$api.getStorage(MS)||0];
    codeData=$api.getStorage(codeDataKey);
    if(user){
      $api.dom('#username').value=user.username;
      if(codeData){
        $api.dom('#count').value=codeData.length;
      }else{
        $api.dom('#count').value=0;
      }
    }else{
      api.closeToWin({
          name: 'root'
      });
    }
  };

  function synchData(){

     let repertoryid = $api.dom('#chid').value;
     if(!repertoryid){
        toast.fail({
          title:'请选择仓库号',
          duration:2000
        });
        return false;
     }
     let repertoryno = $api.dom('#hw').value;
     codeData =$api.getStorage(codeDataKey);

    if(!codeData||!codeData.length>0){
      toast.fail({
        title:'条码为0',
        duration:2000
      });
        return false;
    }

    const dialog = new auiDialog({});
    dialog.alert({
      title:'温馨提示',
      msg:'你确定要同步数据吗，此操作不可逆，请慎重！',
      buttons:['取消','确定']
    },function(ret){
        if('2'==ret.buttonIndex){

          let param ={
            codeArray:codeData,
            repertoryid:repertoryid,
            repertoryno:repertoryno,
            state:$api.getStorage(MS)||0
          };
         console.info("==>"+JSON.stringify(param));
          api.showProgress({
              style: 'fade',
              animationType: 'zoom',
              title: '数据正在同步',
              text: '请耐心等待结果',
              modal: true
          });

          ajaxRequest('/barscan/synchData','post',param,function(ret,err){
              api.hideProgress();
                //更新成功
               if(ret.result){
                      toast.success({
                        title:'同步成功',
                        duration:2000
                      });
               }else{
                 toast.fail({
                   title:'同步失败',
                   duration:2000
                 });
               }
          });

        }
    });

  }

  function openSelect(){
    api.showProgress({
        style: 'default',
        animationType: 'zoom',
        title: '努力加载中...',
        text: '先喝杯茶...',
        modal: false
    });

    ajaxRequest('/barscan/getRepertoryList','get',null,function(ret,err){
      api.hideProgress();
      if(ret){
        if(ret.result){
          let items =ret.list;
          const UIMultiSelector = api.require("UIMultiSelector");
          UIMultiSelector.open({
            rect:{
              h:200
            },
            text:{
              title:'选择仓库号',
              leftBtn:'取消',
              rightBtn:'确定'
            },
            max:0,
            singleSelection:true,
            styles:{
              mask:'rgba(0,0,0,0)',
              title:{
                bg:'rgb(245,245,245,1)',
                color:'rgb(184,209,5)',
                size:16,
                h:44
              },
              leftBtn:{
                bg:'rgb(9,169,244,1)',
                w:80,
                h:35,
                marginT:5,
                marinL:8,
                color:'rgb(0,0,0)',
                size:16
              },
              rightBtn:{
                bg:'#03a9f4',
                w:80,
                h:35,
                marginT:5,
                marginR:8,
                color:'rgb(0,0,0)',
                size:16
              },
              item:{
                h:44,
                bg:'#fff',
                bgActive:'#ffc107',
                color:'#444',
                active:'#ffffff',
                highlight:44,
                size:18,
                lineColor:'#f2f2f2',
                textAlign:'center'
              }
            },
            animation:true,
            items:items
          },function(ret,err){
            if(ret){
               //console.info("ret"+JSON.stringify(ret));
              if(ret.eventType==="clickRight"){
                 let im = ret.items[0];
                if(im&&"selected"===im.status){
                   $api.dom('#chid').value=im.value;
                   $api.dom('#chtxt').value=im.text;
                   UIMultiSelector.hide();
                 }
              }

              if("clickLeft"===ret.eventType){
                 UIMultiSelector.hide();
              }

              if("clickItem"===ret.eventType){
                let im = ret.items[0];

                if(im&&"selected"===im.status){
                  toast.custom({
                    title:im.text,
                    html:'<i class="aui-iconfont aui-icon-home"></i>',
                    duration:600
                  });
                }

              }

            }else{
              alert(JSON.stringify(err));
            }
          });
        }
      }
    });

  };


</script>
</html>
